package org.kms.Controllers;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.kms.dao.kmsRoleDao;
import org.kms.pojo.KmsRole;
import org.kms.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@CrossOrigin("*")
@RequestMapping("/Role")
public class Role {

    @Autowired
    private kmsRoleDao kmsRoleDao;



    @RequestMapping("/all")
    @ResponseBody
    public List<KmsRole> all() throws Exception{
        return kmsRoleDao.getAll();
    }


    @RequestMapping("/rolelist")
    @ResponseBody
    public List<KmsRole> roleList()throws Exception{
        return kmsRoleDao.getAll();
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<KmsRole>> index(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit,KmsRole condition)throws Exception{
        Page<KmsRole> pages = PageHelper.startPage(page,limit);
        List<KmsRole> list =kmsRoleDao.getConditionList(condition);
        return new ResponseResult(list,pages.getTotal());
    }

   @RequestMapping("/roledelete")
    @ResponseBody
    public ResponseResult roledelete(Integer roleId)throws Exception{
        kmsRoleDao.delete(roleId);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/roleadd")
    @ResponseBody
    public ResponseResult roleadd(KmsRole kmsRole)throws Exception{
        kmsRoleDao.add(kmsRole);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/roleupdate")
    @ResponseBody
    public ResponseResult roleupdate(KmsRole kmsRole)throws Exception{
        kmsRoleDao.update(kmsRole);
        return ResponseResult.createSuccessResult();
    }


  /*  @RequestMapping("/batchdelete")
    @ResponseBody
    public ResponseResult batchdel(Integer [] roleId) throws Exception{
        kmsRoleDao.batchDelete(roleId);
        return ResponseResult.createSuccessResult();
    }*/

}
